<template>
  <a-form-model :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
    <a-form-model-item label="账号">
      <a-input v-model="form.username"/>
    </a-form-model-item>
    <a-form-model-item label="密码">
      <a-input v-model="form.password"/>
    </a-form-model-item>

    <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
      <a-button :disabled="form.username === '' || form.password === ''" type="primary" @click="onSubmit">
        登录
      </a-button>
      <a-button style="margin-left: 10px;" @click="onReset">
        重置
      </a-button>
    </a-form-model-item>

  </a-form-model>
</template>

<script>
import WebIM from '../utils/WebIM'

export default {
  name: "Login",
  data() {
    return {
      labelCol: {span: 4},
      wrapperCol: {span: 14},
      form: {
        username: 'lb1234',
        password: 'lb123456'
      },
    };
  },
  methods: {
    onSubmit() {
      let that =this;
      let options = {
        apiUrl: WebIM.config.apiURL,
        user: that.form.username,
        pwd: that.form.password,
        appKey: WebIM.config.appKey,
        success: function (res) {
          let token = res.access_token;
          WebIM.utils.setCookie('webim_' + that.form.username, token, 1);
        },
      };
      this.$store.state.login.username=this.form.username;
      this.$store.state.login.password=this.form.password;
      WebIM.conn.open(options);
    },
    onReset() {
      this.form.username = '';
      this.form.password = '';
    }
  },
}
</script>

<style scoped>

</style>
